package com.wind.trademark.common.aop;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.util.StopWatch;

@Aspect
public class LogAspect {

	@Around("* com.wind.trademark..service.*Service.*(..)")
	public Object doBasicProfiling(ProceedingJoinPoint joinPoint) throws Throwable {
		Log logger = LogFactory.getLog(joinPoint.getSignature().getDeclaringType());
		logger.debug("Start Function :" + joinPoint.getSignature().getDeclaringType());
		StopWatch stopWatch = new StopWatch();
		Object retVal = null;
		try {
			stopWatch.start();
			retVal = joinPoint.proceed();
			stopWatch.stop();
			logger.info("Execution time: " + stopWatch.getTotalTimeMillis() + " ms");
		} catch (Throwable e) {
			logger.error("Execution time: " + stopWatch.getTotalTimeMillis() + " ms");
			throw e;
		}
		logger.debug("End Function :" + joinPoint.getSignature().getDeclaringType());
		return retVal;
	}

}
